import sys
import random


def f(n,b):
    import string
    ss=string.digits+string.ascii_uppercase
    r=[]
    while n:
        n,m=divmod(n,b)
        r.append(ss[m])
    r.reverse()
    r=''.join(map(str,r))
    return r

a=[[15,2],
   [39,8],
   [65,16],
   [15,16],
   [231223,16],
   [222,18],
   [11111,24],
   [1024,32],
   [35035167,36],
   [77777,36]    
  ]

for i  in range(10):
    fin = open('{}.in'.format(i+1),'w')
    fout = open('{}.out'.format(i+1),'w')
    print(*a[i],file=fin)
    print(f(*a[i]),file=fout)
    fin.close()
    fout.close()

